package com.ruiysoft.service.order.util;

import com.ruiysoft.entity.order.OrderDetail;
import com.ruiysoft.entity.order.OrderSkuInfo;
import com.ruiysoft.service.order.bean.OrderSkuDto;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Date : 2018/11/10
 *
 * @author WenJialu
 */
public enum OrderWechatUtil {

	INSTANCE;

	public List<OrderSkuDto> assembleOrderSkuDtos(List<OrderDetail> orderDetails, List<OrderSkuInfo> orderSkuInfos, Map<Long, String> orderSkuPicsMap) {
		if (null == orderDetails || orderDetails.isEmpty()) {
			return Collections.emptyList();
		} else {
			Map<Long, OrderSkuInfo> skuInfoMap = orderSkuInfos.stream().collect(Collectors.toMap(OrderSkuInfo::getSkuId, skuInfo -> skuInfo));
			return orderDetails.stream().map(orderDetail -> {
				OrderSkuDto skuDto = new OrderSkuDto();
				skuDto.setSkuId(orderDetail.getSkuId());
				skuDto.setMerchandiseName(skuInfoMap.getOrDefault(orderDetail.getSkuId(), new OrderSkuInfo()).getMerchandiseName());
				skuDto.setPriceStrategy(orderDetail.getPriceStrategy());
				skuDto.setQuantity(orderDetail.getQuantity());
				skuDto.setUnitPrice(orderDetail.getUnitPrice());
				skuDto.setVirtualCoinPrice(orderDetail.getVirtualCoinPrice());
				skuDto.setVirtualCoin(orderDetail.getVirtualCoin());
				skuDto.setTotalAmount(orderDetail.getTotalAmount());
				skuDto.setTotalCash(orderDetail.getTotalCash());
				skuDto.setImgUrl(orderSkuPicsMap.get(orderDetail.getSkuId()));
				return skuDto;
			}).collect(Collectors.toList());
		}
	}
	
}
